#include <opencv2/opencv.hpp>
#include "../processing/processing.h"

static const int table[64][2] = {
        -1, -1,
        0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0,
        6, 1, 7, 1, 8, 1,
        6, 2, 7, 2, 8, 2,
        6, 3, 7, 3, 8, 3,
        0, 4, 1, 4, 2, 4, 3, 4, 4, 4, 5, 4, 6, 4, 7, 4, 8, 4, 9, 4, 10, 4, 11, 4, 12, 4, 13, 4, 14, 4,
        6, 5, 7, 5, 8, 5,
        6, 6, 7, 6, 8, 6,
        6, 7, 7, 7, 8, 7,
        0, 8, 1, 8, 2, 8, 3, 8, 4, 8, 5, 8, 6, 8, 7, 8, 8, 8, 9, 8, 10, 8, 11, 8, 12, 8, 13, 8, 14, 8,
};

void label2coor(int label, int& x, int& y) {
    if (label >= -1 && label <= 63) {
        x = table[label][0];
        y = table[label][1];
    }
    else {
        x = -1;
        y = -1;
    }
}

static const uint etable[9][15] = {
    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0,
    0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
};

bool isWorkedEletroid(int x, int y) {
    if (x < 0 || y < 0) return false;
    return etable[y][x] == 1;
}